{% extends "../layouts/admin.html" %} {% block content %}
<header class="header navbar bg-white shadow">
  <a href="/weixin/mass/index?id={{wxid}}" data-pjax id="_reload"></a>
  <a class="btn btn-primary navbar-btn" href="/weixin/mass/news?id={{wxid}}" data-pjax><i class="ti-book"></i> 素材管理</a>
  <div class="btn-group">
    <div >
      <select id="wxid" name="wxid" class="form-control">
         {% for item in wxlist %}
        <option value="{{item.id}}" {% if item.id==wxid %}selected{% endif %}>{{item.appname }}</option>
        {% endfor %}
      </select>
    </div>
  </div>
  <div class="pull-right">
    <div class="btn-group tool-button">
      <a class="btn btn-info navbar-btn" href="/weixin/mass/send?id={{wxid}}" data-pjax><i class="ti-export"></i> 群发消息</a>
    </div>
  </div>
</header>
<div class=panel-body style="padding-top: 50px;">
  <div class="table-responsive no-border">
    <input id="unitid" type="hidden">
    <table class="table table-bordered table-striped mg-t datatable">
      <thead>
      <tr>
        <th>群发名称</th>
        <th>群发类型</th>
        <th>群发范围</th>
        <th>群发时间</th>
        <th>操作</th>
    </table>
  </div>
</div>
<div id="dialogDetail" class="modal fade bs-modal" tabindex="-3" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
    </div>
  </div>
</div>
<script language="JavaScript">
  var datatable;
  function initDatatable() {
    datatable = $('.datatable').DataTable({
      "dom": '<"toolbar">frtip',
      "searching": false,
      "processing": false,
      "serverSide": true,
      "select": true,
      "ordering": true,
      "language": {
        "url": "/assets/plugins/datatables/cn.json"
      },
      "preDrawCallback": function () {
        sublime.showLoadingbar($(".main-content"));
      },
      "drawCallback": function () {
        sublime.closeLoadingbar($(".main-content"));
      },
      "ajax": {
        "url": "/weixin/mass/index",
        "type": "post",
        "data": function (d) {
          d.wxid='{{wxid}}';
          d.nickname = $('#nickname').val();
          d.content=$('#content').val();
        }
      },
      "order": [[3, "desc"]],
      "columns": [
        {"data": "name", "bSortable": true},
        {"data": "type", "bSortable": true},
        {"data": "scope", "bSortable": true},
        {"data": "create_time", "bSortable": true}
      ],
      "columnDefs": [
        {
          "render": function (data, type, row) {
            if (data=='text') {
              return '文本';
            }
            return '图文';
          },
          "targets": 1
        },
        {
          "render": function (data, type, row) {
            if (data=='all') {
              return '全部会员';
            }
            return '会员列表';
          },
          "targets": 2
        },
        {
          "render": function (data, type, row) {
            if (data) {
              return new Date(parseInt(data)).format("yyyy-MM-dd hh:mm:ss");
            }
            return '';
          },
          "targets": 3
        },
        {
          "render": function (data, type, row) {
            var str='<div class="btn-group"><button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">' +
              ' <i class="ti-settings"></i> <span class="ti-angle-down"></span></button><ul class="dropdown-menu" role="menu">';
            str+= '<li><a href="/weixin/mass/detail?id=' + row.id + '"  data-toggle="modal" data-target="#dialogDetail">查看</a></li>' +
              '</ul></div>';
            return str;
          },
          "targets": 4
        }
      ]
    });
    datatable.on('click', 'tr', function () {
      $(this).toggleClass('selected');
    });
    $("#searchBtn").on('click', function () {
      datatable.ajax.reload();
    });
  }
  $(function () {
    initDatatable();
    $("#wxid").on("change",function(){
      $("#_reload").attr("href","/weixin/mass/index?id="+$(this).val());
      $("#_reload").trigger("click");
    });
    $("#dialogDetail").on("hidden.bs.modal", function() {
      $(this).removeData("bs.modal");
    });
  });
</script>
{% endblock %}